/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.systemView;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.ruipengkj.commons.util.MatcherFormatUtil;
import com.ruipengkj.commons.util.display.ClientDisplay;
import com.ruipengkj.component.JLabelJTextFieldComponent;
import com.ruipengkj.view.base.BasePanel;

/**
 * 说明：
 * 客显测试
 * @Author：李智深
 * @Date：2012-03-23
 */
public class ParamDisplayPanel extends BasePanel{

	
	private static final long serialVersionUID = 1L;
	
	private JButton offButton=new JButton("状态灯全灭");
	private JButton priceButton=new JButton("单价状态灯");
	private JButton totalButton=new JButton("总计状态灯");
	private JButton amountButton=new JButton("收款状态灯");
	private JButton chagneButton=new JButton("找零状态灯");
	private JButton strButton=new JButton("显示 ");
	
	private JLabelJTextFieldComponent strTF=new JLabelJTextFieldComponent("顾客显示屏显示的字符:", 30);
	public ParamDisplayPanel(){
//		this.setLayout(new BorderLayout());
		this.init();
		this.initListener();
	}
	
	private void init(){
		JPanel main_jp=new JPanel();
		BoxLayout boxLayout=new BoxLayout(main_jp, BoxLayout.Y_AXIS);
		main_jp.setLayout(boxLayout);
		
		FlowLayout flowLayout=new FlowLayout(FlowLayout.LEFT);
		JPanel jp1=new JPanel(flowLayout);
		jp1.add(offButton);
		jp1.add(priceButton);
		jp1.add(totalButton);
		jp1.add(amountButton);
		jp1.add(chagneButton);
		
		JPanel jp2=new JPanel(flowLayout);
		strTF.getText().setText("0123456789");
		jp2.add(strTF);
		jp2.add(strButton);
	
		main_jp.add(jp1);
		main_jp.add(jp2);
		this.add(main_jp);
	}

	private void initListener(){
		offButton.addActionListener(this);
		priceButton.addActionListener(this);
		totalButton.addActionListener(this);
		amountButton.addActionListener(this);
		chagneButton.addActionListener(this);
		strButton.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		Map map = new HashMap();  
        map.put(ClientDisplay.PARAM_PORT_STR, "COM1");//端口
        map.put(ClientDisplay.PARAM_BAUD_RATE_STR, "2400"); //波特率 
        map.put(ClientDisplay.PARAM_DISPLAY_RATE_STR, "8");  //位数
        map.put(ClientDisplay.PARAM_DATA_STR, "");  //显示数据
		if(e.getSource()==offButton){
			//状态灯全灭
	        map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_OFF);//状态灯  
	      
		}else if(e.getSource()==priceButton){
			//单价状态灯
		     map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_PRICE);//状态灯  
		}else if(e.getSource()==totalButton){
			//总计状态灯
		     map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_TOTAL);//状态灯  
		}else if(e.getSource()==amountButton){
			//收款状态灯
		     map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_AMOUNT);//状态灯  
		}else if(e.getSource()==chagneButton){
			//找零状态灯
		     map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_CHAGNE);//状态灯  
		}else if(e.getSource()==strButton){
			//显示
			String temp=strTF.getText().getText().trim();
			if(temp.equals("")||temp.length()>10){
				JOptionPane.showMessageDialog(null, "显示数据不能为空，且不能大于10位");
				return;
			}
			if(!MatcherFormatUtil.MatcherNumberScheme(temp)){
				JOptionPane.showMessageDialog(null, "显示数据只能为数字");
				return;
			}
			 map.put(ClientDisplay.PARAM_DATA_STR, temp);  //显示数据
		     map.put(ClientDisplay.PARAM_STATE_STR, ClientDisplay.DISPLAY_STATE_AMOUNT);//状态灯  
		}
		try {  
			ClientDisplay.sendDisplay(map);  
        } catch (Exception ee) {  
            ee.printStackTrace();  
        }  
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}
}
